﻿using com.iot.core.data.entity;

using System.Linq.Dynamic.Core;
using Microsoft.EntityFrameworkCore;

namespace com.iot.core.data.service
{
    public class HtUserRoleService : BaseService<HtUserRole>, IHtUserRoleService
    {
        public async Task<List<IdNameDto>>  GetRolesAsync(long uid, long did)
        {
            var DB = BaseMapper.DB;
            var l = await DB.Set<HtUserRole>()
              .Join(
                    DB.Set<HtRole>(),
                    a => new { HTUser_Id = a.HtuserId, HtdeptId = a.HtdeptId,HtroleId=a.HtroleId, UDeleted=a.Deleted, RDeleted = false  },
                    b => new { HTUser_Id = uid,        HtdeptId = did,       HtroleId=b.Id,       UDeleted = false,   RDeleted = b.Deleted},
                    (a, b) => new IdNameDto { Id = b.Id, Name = b.Name }
                    )
              .ToListAsync();
            return l;
        }

        public async Task<List<IdNameAttrDto>> GetRolesAsync(List<long> luid, long did)
        {
            var DB = BaseMapper.DB;
            var l = await DB.Set<HtUserRole>()
                .Where(a=>luid.Contains(a.HtuserId) )
              .Join(
                    DB.Set<HtRole>(),
                    a => new { HtdeptId = a.HtdeptId, HtroleId = a.HtroleId, UDeleted = a.Deleted, RDeleted = false },
                    b => new { HtdeptId = did,        HtroleId = b.Id,       UDeleted = false,     RDeleted = b.Deleted },
                    (a, b) => new IdNameAttrDto { Id = b.Id, Name = b.Name,Id1=a.HtuserId }
                    )
              .ToListAsync();
            return l;
        }
    }
}
